import Store from '@/store/index'

export function setFullScreen(docElement) {
    let type = Store.state.control.isFullScreen ? 'exit' : 'open'
    let api = dakaMapFullScreenElementApi(type)



    if(type == 'open') {
        if(docElement) {
            docElement[api]()
        } else {
            document.documentElement[api]()
        }
        // dakaMapRef.value[api]()
    } else if(type == 'exit') {
        document[api]()
    }
}
function dakaMapFullScreenElementApi(type) {
    let requestFullScreen = ['RequestFullScreen', 'mozRequestFullScreen', 'webkitRequestFullScreen', 'msRequestFullscreen'];
    let exitFullScreen = ['exitFullscreen', 'mozCancelFullScreen', 'webkitExitFullscreen', 'msExitFullscreen'];

    let apiList
    if(type == 'open') {
        apiList = requestFullScreen
        let api
        for(let i = 0; i < apiList.length; i++) {
            if(document.documentElement[apiList[i]]) {
                api = apiList[i]
            }
        }
        return api
    }
    if(type == 'exit') {
        apiList = exitFullScreen
        let api
        for(let i = 0; i < apiList.length; i++) {
            if(document[apiList[i]]) {
                api = apiList[i]
            }
        }
        return api
    }
}
